home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 04 / 4 / DISK0440.ZIP / FILEFIX.PAS < prev    next >
Pascal/Delphi Source File  |  1985-05-14  |  7KB  |  254 lines

  1.  
  2. program fix;
  3.  
  4.  { The following program is designed to 'massage' a text file that terminates }
  5.  { lines a with a CR or CR/LF into a source file for WordPlus by PSI.         }
  6.  {   Written By :                                                             }
  7.  {               Bill Buoy                  5-12-85.                          }
  8.  { This is Version 2.01                                                       }
  9.  { The original was written in PCjr Basic   2-17-85.                          }
  10.  
  11.  { The process is as follows:
  12.        Open the input file (from the commandline if invoked with with
  13.        filename(s) in the call)
  14.  
  15.        Open an output file with an extension of .FIX.
  16.  
  17.        While not end_of_file (input file)
  18.  
  19.                1. Read a line
  20.                   Append an chr(Endline) marker
  21.                   Find position to start padding
  22.                   Add pad characters to line
  23.                   Replace the '@' symbol with W+ 'open format marker
  24.                   For each character in the line
  25.                       Mask the high order bit to 0.
  26.                   Write the line to the output file.
  27.  
  28.  
  29.        Endwhile end_of_file
  30.  
  31.  }
  32.  {      ********************* Instructions to User **********************
  33.  
  34.     You may either call the program from DOS and allow the program to request
  35.     the filename to operate on, or from the dr:> prompt, type the input and
  36.     output filenames, separated from the call to FIX by spaces.  This would
  37.     look like this:
  38.                    A>FIX INPUTNAME.EXT OUTPUTNAME.EXT
  39.       where INPUTNAME.TXT and OUTPUTNAME.TXT are not equal
  40.  
  41.                                 or
  42.  
  43.                    A>FIX INPUTNAME.EXT
  44.       and let FIX supply the output name (INPUTNAME.FIX).
  45.  
  46.  }
  47. const
  48.  
  49.         ExtName    ='.FIX';
  50.     Screenwidth    =80;
  51.        Oldfmtmk    ='@';
  52.        Newfmtmk    =$10;
  53.         Endline    =$11;
  54.             Pad    =0;
  55.             Mask   =127;
  56.  
  57. type
  58.      filestring    =string[14];
  59.             ext    =string[4];
  60.      workstring    =string[255];
  61.  
  62. var
  63.  
  64.       Source, Dest:  Text;
  65.        FromName,
  66.             ToName:  filestring;
  67.              Temp,
  68.              Indx,
  69.             Count,
  70.              Repl,
  71.           Padfrom,
  72.                Len:  byte;
  73.               Line:  workstring;
  74. Procedure init;
  75.  
  76.    Function BuildName(var RootName: filestring; Extension: ext): filestring;
  77.  
  78.         var
  79.             delpos: integer;
  80.           workname: filestring;
  81.  
  82.         begin
  83.                delpos:=Pos('.',RootName);
  84.  
  85.                case delpos of
  86.  
  87.                     0:     BuildName:=concat (RootName, Extension);
  88.  
  89.                 1..10:     begin
  90.                              workname:=copy (RootName,1,delpos-1);
  91.                              BuildName:=concat (workname, Extension);
  92.                            end;
  93.  
  94.                  else      begin
  95.                              Writeln('IMPROPER FILENAME');
  96.                              Halt;
  97.                             end;
  98.               end {case delpos};
  99.  
  100.         end {function buildname};
  101.  
  102.  
  103. Begin
  104.  
  105.      {initialize variables}
  106.        clrscr;
  107.          FromName:='';
  108.            ToName:='';
  109.           Padfrom:=0;
  110.               Len:=0;
  111.              Repl:=0;
  112.              Temp:=0;
  113.  
  114.  
  115.      case Paramcount of
  116.           0: begin
  117.                 Write('Enter Source File Name (name.ext) ');
  118.                 Readln(FromName);
  119.                 ToName:=BuildName(FromName,ExtName);
  120.              end;
  121.  
  122.           1: begin
  123.                FromName:=ParamStr(1);
  124.                ToName:=BuildName(FromName,ExtName);
  125.              end;
  126.  
  127.           2: begin;
  128.                 FromName:=Paramstr(1);
  129.                 ToName:=Paramstr(2);
  130.                 If FromName=ToName then
  131.                         begin
  132.                                 Writeln('Cannot overwrite input file');
  133.                                 Halt;
  134.                         end;
  135.              end;
  136.  
  137.       else   begin
  138.                Writeln('Too Many Parameters on command line.....');
  139.                halt;
  140.              end;
  141.    end; {case}
  142.  
  143.  
  144.      if ToName = '' then
  145.  
  146.              ToName:=BuildName(FromName,ExtName);
  147.  
  148.      if Pos('.',ToName)=0 then
  149.  
  150.              ToName:=BuildName(ToName,ExtName);
  151.  
  152.  
  153. end {procedure getname};
  154.  
  155. Procedure access_files;
  156.  
  157.        Function Open(var fp:text; name: Filestring): boolean;
  158.                begin
  159.                     Assign(fp,Name);
  160.                     If IOresult <> 0 then
  161.                        begin
  162.                             Open := False;
  163.                             close(fp);
  164.                         end
  165.                          else
  166.                              Open := True;
  167.                end { Open };
  168.  
  169.     begin
  170.  
  171.          if not open (Source, fromname) then
  172.             begin
  173.                   writeln ('ERROR......file not found');
  174.                  halt;
  175.             end;
  176.  
  177.          reset (Source);
  178.  
  179.          if not open (Dest, toname) then
  180.             begin
  181.                  writeln ('ERROR......file could not be opened for output');
  182.                  close (Source);
  183.                  halt;
  184.             end;
  185.  
  186.          rewrite (Dest);
  187.  
  188.     end {access files};
  189.  
  190. Procedure Padline;
  191.     begin
  192.       Line:=concat(Line,chr(Pad));
  193.     end;
  194.  
  195.  
  196. Function Maskline(NewLine: workstring):workstring;
  197.     var
  198.        Templine: workstring;
  199.  
  200.     begin
  201.         Templine:='';
  202.         for Indx:=1 to Len do
  203.          begin
  204.             Temp:=ord(NewLine[Indx]);
  205.             Temp:=Temp AND Mask;
  206.             Templine:=Concat(Templine,Chr(Temp));
  207.          end;
  208.          Maskline:=Templine;
  209.     end;
  210.  
  211.  
  212.  
  213. Procedure process_files;
  214.    begin
  215.           While not eof(Source) do begin
  216.  
  217.                 Readln (Source,Line);
  218.                 Line:=Concat(Line,chr(Endline));
  219.                 Len:=Length (Line);
  220.                 Line:=Maskline(line); {remove special or graphics characters}
  221.                 Padfrom:=Len mod Screenwidth;
  222.                 Repl:=Pos (Oldfmtmk,Line);
  223.                 If Repl <> 0 then
  224.                  begin
  225.                    delete (line,repl,1);
  226.                    insert (chr(Newfmtmk),line,repl);
  227.                  end;
  228.                 If Len < 80 then
  229.                       for count:=len+1 to screenwidth do
  230.                        Padline
  231.                 Else for count:=padfrom+1 to screenwidth do
  232.                        Padline;
  233.                 write (dest,line);
  234.                 write (line);
  235.             end;
  236.    end;
  237.  
  238.  
  239. BEGIN {main program}
  240.      init;
  241.      writeln('Accessing file ',FromName,' for input.');
  242.      access_files;
  243.      writeln('Reworked file will be ',ToName,'.');
  244.      process_files;
  245.      writeln('Rework completed.');
  246.      close (Source);
  247.      close (Dest);
  248.      writeln (chr(7));
  249. end.
  250.  
  251.  
  252.  
  253.  
  254.